import { queryTeachSchedule } from '@/api/selfStudy/class.js';
const classCommonFun = {
    data() {
        return {};
    },
    methods: {
        //按照课程和日期整合排课数据
        dealClassNumberList(classNumbers) {
            let arr = {};
            let calendarEvents = [];
            classNumbers.sort(function (a, b) {
                let timetampa = new Date(a.classNumberList[0].startTime).getTime();
                let timetampb = new Date(b.classNumberList[0].startTime).getTime();
                return timetampa > timetampb ? 1 : -1;
            });
            classNumbers.forEach((classNumber) => {
                let classId = classNumber.classId;
                let courseId = classNumber.classCourseId;
                let dateStr = classNumber.classNumberList[0].startTime.split(' ')[0]; //年月日
                if (!arr[classId]) {
                    arr[classId] = {};
                }
                if (!arr[classId][courseId]) {
                    arr[classId][courseId] = {};
                }
                if (!arr[classId][courseId][dateStr]) {
                    arr[classId][courseId][dateStr] = {
                        //					className:classInfo.className,
                        classId: classId,
                        courseId: courseId,
                        courseDictCode: classNumber.courseDictCode,
                        courseName: classNumber.classCourseName,
                        classNumberList: classNumber.classNumberList, //课程课节
                        timestamp: new Date(classNumber.classNumberList[0].startTime).getTime(),
                        startDateArr: [classNumber.classNumberList[0].startTime], //所有课节的开始时间集合
                        endDateArr: [classNumber.classNumberList[0].endTime], //所有课节的结束集合
                        dateStr: dateStr, //整个排课日期
                        start: classNumber.classNumberList[0].startTime, //整个排课的开始时间
                        end: classNumber.classNumberList[0].endTime, //整个排课的结束时间
                    };
                    calendarEvents.push(arr[classId][courseId][dateStr]);
                } else {
                    arr[classId][courseId][dateStr].classNumberList = arr[classId][courseId][
                        dateStr
                    ].classNumberList.concat(classNumber.classNumberList);
                    arr[classId][courseId][dateStr].startDateArr = arr[classId][courseId][
                        dateStr
                    ].startDateArr.concat([classNumber.classNumberList[0].startTime]);
                    arr[classId][courseId][dateStr].endDateArr = arr[classId][courseId][
                        dateStr
                    ].endDateArr.concat([classNumber.classNumberList[0].endTime]);
                    //整个排课的开始时间和结束时间
                    let startTimeArr = arr[classId][courseId][dateStr].startDateArr;
                    let endTimeArr = arr[classId][courseId][dateStr].endDateArr;
                    let timeArr = [...startTimeArr, ...endTimeArr].sort();
                    arr[classId][courseId][dateStr].start = timeArr[0];
                    arr[classId][courseId][dateStr].end = timeArr[timeArr.length - 1];
                }
            });
            return calendarEvents;
        },
    },
};

export default classCommonFun;
